<html>
<head>
<title>Elements location updated after redirect</title>
<script type="text/javascript" src="/shared/scripts/testcase.js"></script>
<script type="text/javascript" src="/shared/scripts/misc.js"></script>
<script type="text/javascript">
if (window.addEventListener) {
	window.addEventListener('load', f, false);
} else if (window.attachEvent) {
	window.attachEvent('onload', f);
} else {
	window.onload = f;
}

function insert_elements(xhr, tc) {
	var insert_head = document.getElementsByTagName('head')[0];
	var insert_body = document.getElementById('id1');
	var redirect = "/redirect?loc=http://victim.com/shared/resources/";
	// link element
	var linkt = new tElement("link", "link_test");
	linkt.orig_loc = redirect+"cssRules.css"
	var link_attribs = new Array("id", linkt.dom_id,
								 "href", linkt.orig_loc,
								 "rel","stylesheet",
								 "type","text/css");
		
	linkt.loc_attrib = "href";
	linkt.dom_loc = insert_head;
	linkt.insertAttributes(link_attribs);
	linkt.insertToDom();

	// script element
	var scriptt = new tElement("script","script_test");
	scriptt.orig_loc = redirect+"script.js"
	var script_attribs = new Array("id", scriptt.dom_id,
								   "src", scriptt.orig_loc,
								   "type", "text/javascript");
	scriptt.loc_attrib = "src";
	scriptt.dom_loc = insert_head;
	scriptt.insertAttributes(script_attribs);
	scriptt.insertToDOM();
	
	// img element
	var imgt = new tElement("img", "img_test");
	imgt.orig_loc = redirect+"4x4.png";
	var img_attribs = new Array("id", imgt.dom_id,
								"src", imgt.orig_loc);
	imgt.loc_attrib = "src";
	imgt.dom_loc = insert_body;
	imgt.insertAttributes(img_attribs);
	imgt.insertToDOM();
	
	// img element (usemap attrib)
	var imgt_u = new tElement("img", "img_usemaptest");
	imgt_u.orig_loc = redirect+"data.html";
	var img_attribs = new Array("id", imgt_u.dom_id,
								"src", "/shared/resources/4x4.png",
								"usemap", imgt_u.orig_loc);
	imgt_u.loc_attrib = "usemap";
	imgt_u.dom_loc = insert_body;
	imgt_u.insertAttributes(img_attribs);
	imgt_u.insertToDOM();
	
	// iframe element
	var iframet = new tElement("iframe", "iframe_test");
	iframet.orig_loc = redirect+"data.html";
	var iframe_attribs = new Array("id", iframet.dom_id,
								   "src", iframet.orig_loc);
	iframet.loc_attrib = "src";
	iframet.dom_loc = insert_body;
	iframet.insertAttributes(iframe_attribs);
	iframet.insertToDOM();
	
	// input with src attrib, type = image...
	var inputt = new tElement("input", "input_test");
	inputt.orig_loc = redirect+"4x4.png";
	var input_attribs = new Array("id", inputt.dom_id,
								  "type", "image",
								  "src", inputt.orig_loc);
	inputt.loc_attrib = "src";
	inputt.dom_loc = insert_body;
	inputt.insertAttributes(input_attribs);
	inputt.insertToDOM();
	
	var tobjs = new Array(linkt, scriptt, imgt, imgt_u, iframet, inputt);
		 
	// give enough time for the elements to load... (see misc.js)
	setTimeout( (function() { get_loc_results_cb(tc, tobjs); }), 4000);
}

function f() {
	var tc = new TestCase();
	tc.input = 'link, script, img, input and iframe tags';
	tc.description = 'Test if elements location (href/src/data etc) have been updated after a redirect';
	tc.expected_result = 'not updated';
	tc.test_passed = 'true';
	tc.savePreTest(insert_elements);
}

</script>
</head>
<body>
<div id="id1"></div>
</body>
</html>